<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>加减款</title>
	<%@ include file="/view/common/tags.jsp"%>
    <style type="text/css">
        #finDrawClDiv label{line-height: 25px;}
        #finDrawClDiv span{line-height: 25px;}
        #finDrawClDiv2{padding: 12px;}
    </style>
</head>
<body>
	<section class="content">
    	<div class="row">
            <div class="col-md-12">
                <div class="box">
                	<div class="box-body">
						<div class="panel panel-default">
                            <div class="panel-body" style="padding-bottom:5px;">
                                <form class="form-horizontal" action="" method="post" id="dataForm">
                                    <input type="hidden" id="token" name="token" value="" />
                                	<div class="searchMenu">
                                        <div class="col-xs-10">
                                            <div>
                                                <label>操作时间：</label>
                                                <input id="createTimeStart" name="wm[_MORE_EQUAL$CREATE_TIME]" value="${page.wm._MORE_EQUAL$CREATE_TIME}"  type="text"  class="Wdate" 
    											  onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',startDate:'%y-%M-%d 00:00:00',alwaysUseStartDate:true,maxDate:'#F{$dp.$D(\'createTimeEnd\')}',minDate:'#F{$dp.$D(\'createTimeEnd\',{d:-30,H:-23,m:-59,s:-59})}'})" /> 
    											<span class="pull-left">&nbsp;-&nbsp;</span>
    											<input id="createTimeEnd" name="wm[_LESS_EQUAL$CREATE_TIME]" value="${page.wm._LESS_EQUAL$CREATE_TIME}"  class="Wdate" 
    								              onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',startDate:'%y-%M-%d 23:59:59',alwaysUseStartDate:true,minDate:'#F{$dp.$D(\'createTimeStart\')}',maxDate:'#F{$dp.$D(\'createTimeStart\',{d:+30,H:+23,m:+59,s:+59})}'})" />
                                            </div>
                                    	    <div>
                                                <label>加款类型：</label>
                                                <sk:select cssClass="form-control select" id="inOutFlag" name="wm[IN_OUT_FLAG]" value="${page.wm.IN_OUT_FLAG}" >
                                                    <option value="">请选择</option>
                                                    <option value="0">加款</option>
                                                    <option value="1">减款</option>
                                                </sk:select>
                                            </div>
                                    	    <div>
                                                <label>加款原因：</label>
                                                <sk:select cssClass="form-control select" id="reasonIdWm" name="wm[REASON_ID]" value="${page.wm.REASON_ID}" requiredInit="true" ajaxURL="${tradeV1}/tradeState/reasonSelect?wm[REASON_TYPE_ID]=19">
                                                    <option value="">请选择</option>
                                                </sk:select>
                                            </div>
                                        </div>
                                        
                                        <div class="col-xs-10">
                                            <div>
                                    		    <label>相关单号：</label>
                                                <input type="text" class="form-control" name="wm[_LIKE$ORDER_NO]" value="${page.wm._LIKE$ORDER_NO}" placeholder="请输入相关单号">
                                            </div>
                                            <div>
                                    		    <label>操作人：</label>
                                                <input type="text" class="form-control" name="wm[_LIKE$OPERATE_NAME]" value="${page.wm._LIKE$OPERATE_NAME}" placeholder="请输入操作人">
                                            </div>
                                            <div>
                                    		    <label>用户帐号：</label>
                                                <input type="text" class="form-control" name="wm[_LIKE$USER_NAME]" value="${page.wm._LIKE$USER_NAME}" placeholder="请输入用户帐号">
                                            </div>
                                            <div class="mal10" >
                                                <button type="button"  class="btn btn-primary btn-sm"  onclick="findData()"><span class='glyphicon glyphicon-search'></span>查&nbsp;询</button>
                                                <button type="button" class="btn btn-primary btn-sm" style="margin-left: 22px;" onclick="operateOrder()"><span class='glyphicon glyphicon-plus'></span>加减款</button>
                                            </div>
                                        </div>
                                	</div>
                                </form>
                        	</div>
						</div>
                        <table class="table table-hover table-condensed table-bordered table-striped" id="dataTable" >
                            <thead>
                            	<tr>
                                	<th data-field="index" data-align="center" data-formatter="indexFormatter" data-sortable="false" style="width:100px;">序号</th>
                                	<th data-field="financeNo" data-align="center" data-sortable="true">加款单号</th>
                                	<th data-field="orderNo" data-align="center" data-sortable="false">相关单号</th>
                                	<th data-field="userName" data-align="center" data-sortable="false">用户帐号</th>
                                    <th data-field="inOutFlag" data-align="center" data-sortable="false" data-formatter="inOutFlagFormatter">加款类型</th>
                                    <th data-field="tradeMoney" data-align="center" data-sortable="true">操作金额</th>
									<th data-field="reasonDesc" data-align="center" data-sortable="true">加款原因</th>
									<th data-field="operateName" data-align="center" data-sortable="true">操作人</th>
									<th data-field="createTime" data-align="center" data-sortable="true">操作时间</th>
                                	<th data-field="remarkBz" data-align="center" data-sortable="true">备注</th>
                                </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
       	</div>
	</section>
    <div id="finDrawClDiv" style="display: none;">
        <div id="finDrawClDiv2" class="panel panel-body">
        <form class="form-horizontal" action="" method="post" id="finDrawClForm">
            <input type="hidden" id="isReCommit" name="isReCommit" value="0" />
            <input type="hidden" id="token2" name="token" value="" />
            <div class="form-group">
                <label class="col-xs-3 text-right">用户帐号 ：</label>
                <div class="col-xs-8">
                    <textarea id="userName" name="userName" rows="3" cols="50" class="form-control"></textarea>
                    <span style="color: red;">多个用户时用 | 隔开</span>
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-3 text-right">加款类型：</label>
                <div class="col-xs-8">
                    <input type="radio" id="in" name="inOutFlag" value="0"/> 加款&nbsp;&nbsp;
                    <input type="radio" id="out" name="inOutFlag" value="1"/> 减款
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-3 text-right">操作账户：</label>
                <div class="col-xs-8">
                    <input type="radio" id="balance" name="accountFlag" value="1" checked="checked"/> 余额&nbsp;&nbsp;
                    <input type="radio" id="sale" name="accountFlag" value="0"/> 销售
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-3 text-right">金额：</label>
                <div class="col-xs-8">
                    <input type="text" id="tradeMoney" name="tradeMoney" value="" class="form-control" style="width: 80px;"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-3 text-right">相关单号：</label>
                <div class="col-xs-8">
                    <input type="text" id="orderNo" name="orderNo" class="form-control" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-3 text-right">原因：</label>
                <div class="col-xs-8">
                    <sk:select cssClass="form-control select" id="reasonId" name="reasonId" value="" requiredInit="true" ajaxURL="${tradeV1}/tradeState/reasonSelect?wm[REASON_TYPE_ID]=19">
                        <option value="">请选择</option>
                    </sk:select>
                    <input type="hidden" id="reasonDesc" name="reasonDesc" value=""/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-3 text-right">备注：</label>
                <div class="col-xs-8"><textarea id="remarkBz" name="remarkBz" cols="55" rows="3" class="form-control"></textarea></div>
            </div>
        </form>
        </div>
    </div>
   <%@ include file="/view/common/footer.jsp"%>
   <script type="text/javascript" src="${sysManagerV1}/js/My97DatePicker/WdatePicker.js"> </script>
</body>
<script>
// 提示信息
var msgg='<%=request.getAttribute("msg")%>';
if (msgg && msgg!=null && msgg!='null') { 
	  layer.msg(msgg);
}
var tableIndex = 0; // 添加修改的弹出框的ID
var finDrawStateDictList = "" // 订单状态字典数据
var finDrawWayDictList = "" // 提现方式字典数据

$(function(){
    $("#token").val(sessionStorage.getItem("token"));
    $("#token2").val(sessionStorage.getItem("token"));
    
    // 获取订单状态信息
    $.ajax({
    	type: "post",
    	url: "${fundCenterV1}/fundFinanceDrawDetail/finDrawStateDictList",
    	dataType: "json",
    	success: function(data){
    		finDrawStateDictList = data;
    	}
    });
    
    // 加载table 数据
    $("#dataTable").bootstrapTable({ 
        url: "${fundCenterV1}/fundFinanceManualDetail/data.json",
        method:"get", 
        contentType: "application/x-www-form-urlencoded",
        pagination:true,
        sidePagination:"server",
        queryParams: function(params) {
            //alert(JSON.stringify(params));
            return $.extend({}, params, parseJson(decodeURIComponent($("#dataForm").serialize())));     
        }
    });
})

// 加款方式 字段格式化
function inOutFlagFormatter(value, row, index) {
    var finDrawWay = "加款";
    if(value == 1){
    	finDrawWay = "减款";
    }
    return finDrawWay;
}
    
// 查询
function findData(){
   $("#dataTable").bootstrapTable("refresh",{} ); 
} 

// 行点击事件
$(function(){
     $("body").on("click","table>tbody>tr",function(){
      $(this).css("background","#e1ecf1").siblings().css("background","");
   });
})

// 展示订单处理页面
function operateOrder(){
	$("#isReCommit").val(0);
	$("#userName").val("");
    $("#tradeMoney").val("");
    $("#reasonId").val("");
    $("#reasonDesc").val("");
    $("#remarkBz").val("");
	var bjtsIndex = layer.open({
        type: 1,
        title: "提现处理页面",
        area: ['500px', '500px'],
        content: $("#finDrawClDiv"),
        btn: ["确 认", "关 闭"], 
        yes: function(index, layero){
            var userName = $("#userName").val();
            if (!CheckUtil.isNotNull(userName)) {
                layer.msg("请填写用户!");
                return;
            }
            
            var inOutFlag = $("input[name='inOutFlag']:checked").val();
            if(!CheckUtil.isNotNull(inOutFlag)){
                layer.msg("请选择加款类型！");
                return;
            }
            
            var accountFlag = $("input[name='accountFlag']:checked").val();
            if(!CheckUtil.isNotNull(accountFlag)){
                layer.msg("请选择操作账户！");
                return;
            }
            
            var tradeMoney = $("#tradeMoney").val();
            if(!CheckUtil.isInt(tradeMoney, "+")){
                layer.msg("请填写正确的金额！");
                return;
            }
            
            var reasonId = $("#reasonId").val();
            if(!CheckUtil.isNotNull(reasonId)){
                layer.msg("请选择原因！");
                return;
            }
            var reasonDesc = $("#reasonId").find("option:selected").text();
            $("#reasonDesc").val(reasonDesc);
            
            $.ajax({
                type: "post",
                url: "${fundCenterV1}/fundFinanceManualDetail/saveFinanceManualDetail",
                data: new FormData($("#finDrawClForm")[0]),
                dataType:"json",
                processData: false,
                contentType: false,
                async:false,
                success: function(data){
                	$("#isReCommit").val(1); // 防止重复提交
                    if(data.code == 0){
                        layer.msg("保存成功！");
                        layer.close(bjtsIndex);
                        findData();
                    } else if (data.code == -2) {
                        window.location.href = "${sysManagerV1}/";
                    } else{
                        layer.msg(data.message);
                        layer.close(bjtsIndex);
                        findData();
                    }
                }
            });
        }
    });
}
</script>
</html>